package day240815;

import java.util.*;

public class Demo {
    public static void main(String[] args) {
        //1.add(),2.size(),3.isEmpty(),4.clear()
        /*Collection<String> col = new ArrayList<>();
        col.add("123");
        col.add("234");
        col.add("abc");
        System.out.println("打印集合col:"+col);
        System.out.println("集合col的大小:"+col.size());
        boolean b = col.isEmpty();
        System.out.println("集合b是否为空:"+b);
        col.clear();
        System.out.println("清空后的集合col:"+col);*/

        /*//Collection<String> c = new ArrayList<>();
        Collection<String> c = new HashSet<>();
        c.add("one");
        c.add("two");
        c.add("three");
        c.add("four");
        c.add("five");
        boolean b = c.add("one");
        System.out.println("是否插入成功："+b);
        System.out.println("集合c："+c);
        System.out.println("集合c中元素的个数："+c.size());
        System.out.println("集合c是否为空集："+c.isEmpty());

        c.clear();
        System.out.println("集合c已经清空");
        System.out.println("集合c中元素的个数："+c.size());
        System.out.println("集合c是否为空集："+c.isEmpty());*/

        //5.contains(),6.remove(),
        /*//Collection<Point> c = new ArrayList<>();
        Collection<Point> c = new HashSet<>();
        c.add(new Point(1,2));
        c.add(new Point(3,4));
        c.add(new Point(5,6));
        c.add(new Point(7,8));
        c.add(new Point(9,10));
        boolean b = c.add(new Point(1,2));
        System.out.println("是否插入成功："+b);
        System.out.println("集合c"+c);

        Point p1 = new Point(1,2);
        boolean b1 = c.contains(p1);
        System.out.println("集合c是否包含p1："+b1);

        boolean b2 = c.remove(p1);
        System.out.println("是否从集合c中将p1移除："+b2);
        System.out.println("集合c："+c);*/

        /*Collection<Point> c = new ArrayList<>();
        c.add(new Point(1,2));
        c.add(new Point(3,4));
        c.add(new Point(5,6));
        c.add(new Point(7,8));
        c.add(new Point(9,0));
        boolean b1 = c.add(new Point(1,2));
        System.out.println("是否插入成功："+b1);
        System.out.println("集合c："+c);
        Point point = new Point(1,2);
        boolean b = c.contains(point);
        System.out.println("集合c是否包含point："+b);
        boolean b2 = c.remove(point);
        System.out.println("是否从集合c中将point移除："+b2);
        System.out.println(c);*/

        //7.addAll(),8.containsAll(),9.retainAll(),10.removeAll(),11.iterator()
        /*Collection<String> c1 = new ArrayList<>();
        c1.add("java");
        c1.add("c++");
        c1.add(".net");
        System.out.println("集合c1："+c1);

        Collection<String> c2 = new ArrayList<>();
        c2.add("android");
        c2.add("ios");
        c2.add("java");
        System.out.println("集合c2："+c2);

        Collection<String> c3 = new ArrayList<>();
        c3.add("c++");
        c3.add("android");
        c3.add("php");
        System.out.println("集合c3："+c3);

        c1.addAll(c2);
        System.out.println("集合c1："+c1);

        boolean b1 = c1.containsAll(c3);
        System.out.println("集合c1是否包含c3："+b1);

        //c1.retainAll(c3);
        //System.out.println("集合c1与c3取交集："+c1);

        c1.removeAll(c3);
        System.out.println("c1中删去c1与c3的交集："+c1);

        Iterator<String> it = c1.iterator();
        while(it.hasNext()){
            String str = it.next();
            System.out.println(str);
            if("ios".equals(str)){
                it.remove();
            }
        }
        System.out.println("集合c1："+c1);*/
        //12.增强for
        /*String[] array ={"one","two","three","four","five"};
        Collection<String> c = new ArrayList<>();
        c.add("one");
        c.add("two");
        c.add("three");
        c.add("four");
        c.add("five");

        for(int i=0; i<array.length;i++){
            System.out.println(array[i]);
        }
        for(String str:array){
            System.out.println(str);
        }
        System.out.println("====================");
        Iterator<String> it = c.iterator();
        while(it.hasNext()){
            String str = it.next();
            System.out.println(str);
        }
        for(String str:c){
            System.out.println(str);
        }*/

        //List集合常用方法get(),set(),重载remove(),重载add(),subList()
        /*List<String> list = new ArrayList<>();
        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        list.add("five");
        list.add("one");
        System.out.println("list集合："+list);
        String str1 = list.get(2);
        System.out.println("下标为2的元素："+str1);
        for(int i = 0;i<list.size();i++){
            System.out.println("第"+i+"个元素："+list.get(i));
        }
        list.set(2,"six");
        System.out.println("list集合："+list);

        String re = list.remove(2);
        System.out.println("list集合："+list);
        System.out.println("被移除的元素："+re);

        list.add(3,"seven");
        System.out.println("list集合"+list);*/


        List<Integer> list = new ArrayList<>();
        for(int i=0;i<10;i++){
            list.add(i*10);
        }
        System.out.println("list集合："+list);
        List<Integer> subList = list.subList(3,8);
        System.out.println("subList集合"+subList);

        for(int i=0;i<subList.size();i++){
            subList.set(i,subList.get(i)*10);
        }
        System.out.println("subList集合："+subList);
        System.out.println("list集合："+list);

        list.set(3,3000);
        System.out.println("list集合："+list);
        System.out.println("subList集合："+subList);

        list.remove(0);
        System.out.println("list集合："+list);
    }
}
